#pragma once
#ifdef _WINDOWS  //64位系统没有预定义 WIN32
#ifdef __cplusplus
#define DLL_EXPORT_C_DECL extern "C" __declspec(dllexport)
#else
#define DLL_EXPORT_DECL __declspec(dllexport)
#endif
#else
#ifdef __cplusplus
#define DLL_EXPORT_C_DECL extern "C"
#else
#define DLL_EXPORT_DECL extern
#endif
#endif

#ifdef _WINDOWS
#ifdef WIN32
#define WINAPI      __cdecl
#else
#define WINAPI      __stdcall
#endif
#define WIN32_LEAN_AND_MEAN             //  从 Windows 头文件中排除极少使用的信息
#include "stddef.h"
#include "../include/ONSFactory.h"
#include "../include/ONSClientException.h"
#pragma comment(lib, "./lib/ONSClient4CPP.lib")
#else
#define WINAPI
#include "../include/ONSFactory.h"
#include "../include/ONSClientException.h"
#endif

#include <string.h>
#include <iostream>
using namespace ons; //增加命名空间,否则找不到类

// MyMsgListener：创建消费消息的实例
//pushConsumer 拉取到消息后，会主动调用该实例的 consumer 函数
class PushListener : public MessageListener
{
    public:
        PushListener(void);

        typedef void (WINAPI *OnConsumer)(const char *topic, const char *tag, const char *key, const char *id, long long deliver_time, const char *body, int reconsumetimes, long long store_time, long long offset);

        void * _Consumer;
        virtual Action consume(Message &message, ConsumeContext &context)
        {
            if (_Consumer)
            {
                ((OnConsumer)_Consumer)(message.getTopic(), message.getTag(), message.getKey(), message.getMsgID(), message.getStartDeliverTime(), message.getBody(), message.getReconsumeTimes(), message.getStoreTimestamp(), message.getQueueOffset());
            }
            return CommitMessage;
        }
};


// MyMsgListener：创建消费消息的实例
//pushConsumer 拉取到消息后，会主动调用该实例的 consumer 函数
class OrderListener : public MessageOrderListener
{
    public:
        OrderListener(void);

        typedef void (WINAPI *OnConsumer)(const char *topic, const char *tag, const char *key, const char *id, long long deliver_time, const char *body, int reconsumetimes, long long store_time, long long offset);

        void * _Consumer;
        virtual OrderAction consume(Message &message, ConsumeOrderContext &context)
        {
            if (_Consumer)
            {
                ((OnConsumer)_Consumer)(message.getTopic(), message.getTag(), message.getKey(), message.getMsgID(), message.getStartDeliverTime(), message.getBody(), message.getReconsumeTimes(), message.getStoreTimestamp(), message.getQueueOffset());
            }
            return Success;
        }
};